#/bin/bash

# 将一个参数的"...{}".format(name)改为f"...{name}"格式
# 双引号
find . -name "*.py"|xargs sed -n "s/logger.debug(\"\([0-9a-Z ,:_+-<>\.\!]*\){}\".format(\(.*\)))/logger.debug(f\'\1{\2}\')/p"
find . -name "*.py"|xargs sed -i "s/logger.debug(\"\([0-9a-Z ,:_+-<>\.\!]*\){}\".format(\(.*\)))/logger.debug(f\'\1{\2}\')/"
# 单引号
find . -name "*.py"|xargs sed -n "s/logger.debug('\([0-9a-Z ,:_+-<>\.\!]*\){}'.format(\(.*\)))/logger.debug(f\'\1{\2}\')/p"
find . -name "*.py"|xargs sed -i "s/logger.debug('\([0-9a-Z ,:_+-<>\.\!]*\){}'.format(\(.*\)))/logger.debug(f\'\1{\2}\')/"

# 将一个参数的"...{}...".format(name)改为f"...{name}..."格式
# 双引号
find . -name "*.py"|xargs sed -n "s/logger.debug(\"\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\)\".format(\(.*\)))/logger.debug(f\'\1{\3}\2\')/p"
find . -name "*.py"|xargs sed -i "s/logger.debug(\"\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\)\".format(\(.*\)))/logger.debug(f\'\1{\3}\2\')/"
# 单引号
find . -name "*.py"|xargs sed -n "s/logger.debug('\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\)'.format(\(.*\)))/logger.debug(f\'\1{\3}\2\')/p"
find . -name "*.py"|xargs sed -i "s/logger.debug('\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\)'.format(\(.*\)))/logger.debug(f\'\1{\3}\2\')/"

# 将两个参数的"...{}...{}".format(name1, name2)改为f"...{name}...{name2}"格式
# 双引号
find . -name "*.py"|xargs sed -n "s/logger.debug(\"\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\".format(\([^,]*\), \([^,]*\)))/logger.debug(f'\1{\3}\2{\4}')/p"
find . -name "*.py"|xargs sed -i "s/logger.debug(\"\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\".format(\([^,]*\), \([^,]*\)))/logger.debug(f'\1{\3}\2{\4}')/"
# 单引号
find . -name "*.py"|xargs sed -n "s/logger.debug('\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\)'.format(\([^,]*\), \([^,]*\)))/logger.debug(f\1{\3}\2{\4}')/p"
find . -name "*.py"|xargs sed -i "s/logger.debug('\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\)'.format(\([^,]*\), \([^,]*\)))/logger.debug(f'\1{\3}\2{\4}')/"

# 将两个参数的"...{}...{}...".format(name1, name2)改为f"...{name}...{name2}..."格式
# 双引号
find . -name "*.py"|xargs sed -n "s/logger.debug(\"\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\)\".format(\([^,]*\), \([^,]*\)))/logger.debug(f'\1{\4}\2{\5}\3')/p"
find . -name "*.py"|xargs sed -i "s/logger.debug(\"\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\)\".format(\([^,]*\), \([^,]*\)))/logger.debug(f'\1{\4}\2{\5}\3')/"
# 单引号
find . -name "*.py"|xargs sed -n "s/logger.debug(\('[0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\)'.format(\([^,]*\), \([^,]*\)))/logger.debug(f'\1{\4}\2{\5}\3')/p"
find . -name "*.py"|xargs sed -i "s/logger.debug(\('[0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\)'.format(\([^,]*\), \([^,]*\)))/logger.debug(f'\1{\4}\2{\5}\3')/"

# 将三个个参数的"...{}...{}...{}".format(name1, name2, name3)改为f"...{name}...{name2}...{name3}"格式
# 双引号
find . -name "*.py"|xargs sed -n "s/logger.debug(\"\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\".format(\([^,]*\), \([^,]*\), \([^,]*\)))/logger.debug(f'\1{\4}\2{\5}\3{\6}')/p"
find . -name "*.py"|xargs sed -i "s/logger.debug(\"\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\".format(\([^,]*\), \([^,]*\), \([^,]*\)))/logger.debug(f'\1{\4}\2{\5}\3{\6}')/"
# 单引号
find . -name "*.py"|xargs sed -n "s/logger.debug('\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}'.format(\([^,]*\), \([^,]*\), \([^,]*\)))/logger.debug(f'\1{\4}\2{\5}\3{\6}')/p"
find . -name "*.py"|xargs sed -i "s/logger.debug('\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}'.format(\([^,]*\), \([^,]*\), \([^,]*\)))/logger.debug(f'\1{\4}\2{\5}\3{\6}')/"

# 将三个个参数的"...{}...{}...{}...".format(name1, name2, name3)改为f"...{name}...{name2}...{name3}..."格式
# 双引号
find . -name "*.py"|xargs sed -n "s/logger.debug(\"\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\)\".format(\([^,]*\), \([^,]*\), \([^,]*\)))/logger.debug(f'\1{\5}\2{\6}\3{\7}\4')/p"
find . -name "*.py"|xargs sed -i "s/logger.debug(\"\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\)\".format(\([^,]*\), \([^,]*\), \([^,]*\)))/logger.debug(f'\1{\5}\2{\6}\3{\7}\4')/"
# 单引号
find . -name "*.py"|xargs sed -n "s/logger.debug('\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\)'.format(\([^,]*\), \([^,]*\), \([^,]*\)))/logger.debug(f'\1{\5}\2{\6}\3{\7}\4')/p"
find . -name "*.py"|xargs sed -i "s/logger.debug('\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\){}\([0-9a-Z ,:_+-<>\.\!]*\)'.format(\([^,]*\), \([^,]*\), \([^,]*\)))/logger.debug(f'\1{\5}\2{\6}\3{\7}\4')/"
